from ultralytics import YOLO

# Load a model
# model = YOLO("yolo11n.pt")
model = YOLO("best.pt")

# Train the model
train_results = model.train(
    data=r"framework\laji.yaml",  # path to dataset YAML
    epochs=20,  # number of training epochs
    device="cpu",  # device to run on, i.e. device=0 or device=0,1,2,3 or device=cpu
)
# print(train_results)
# Evaluate model performance on the validation set
# metrics = model.val()
# Perform object detection on an image
# results = model("asd241025172828.png")
# results = model(r"ultralytics\data\Images\wheat001.jpg")
# print(results)
# results[0].show()
results = model.predict(r"ultralytics\data\Images\wheat001.jpg",conf=0.1)
print(results)
# for result in results:
#     try:
#         cls = result.boxes.cls.item()
#         conf = result.boxes.conf.item()
#     except Exception:
#         return False
# if self.cls == 0.0 and self.conf >= 0.5:
#     return True
results[0].show()

# Export the model to ONNX format
# path = model.export(format="onnx")  # return path to exported model
